package com.yunbao.hujin.mychoosealbum.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.yunbao.hujin.mychoosealbum.R;
import com.yunbao.hujin.mychoosealbum.model.CameraImageBean;
import com.yunbao.hujin.mychoosealbum.utils.GlideUtil;

import java.util.List;

/**
 * 分类展示图片的适配器 on 2017/11/17.
 */

public class AdapterShowListItem extends BaseAdapter{

    private Context context;
    private List<CameraImageBean> list;

    public AdapterShowListItem(Context context, List<CameraImageBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_showimage_list, parent, false);
            holder = new Holder();
            holder.img = convertView.findViewById(R.id.showlist_img);
            holder.title = convertView.findViewById(R.id.showlist_title);
            holder.counts = convertView.findViewById(R.id.showlist_count);
            convertView.setTag(holder);

        } else {
            holder = (Holder) convertView.getTag();
        }

        GlideUtil.show(context, list.get(position).getTopImagePath())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .placeholder(R.drawable.bg_loading_white)
                .error(R.mipmap.load_failed)
                .into(holder.img);
        holder.title.setText(list.get(position).getFolderName()+":");
        holder.counts.setText(list.get(position).getImageCounts()+"");

        return convertView;
    }


    class Holder {
        ImageView img;
        TextView title, counts;
    }


}
